package com.sugo.seckill.web.login;

import com.sugo.seckill.http.HttpResult;
import com.sugo.seckill.pojo.FrontUser;
import com.sugo.seckill.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 登录Controller
 * @author hubin
 * @date 2020/6/9 16:59
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    UserService userService;

    /**
     *  秒杀系统登录
     * @author hubin
     * @date 2020/6/9 17:02
     */
    @PostMapping(value = "/login")
    public HttpResult login(@RequestBody FrontUser frontUser){
        HttpResult result = userService.login(frontUser);
        return result;
    }

    /**
     * 根据token获取用户信息
     * @author hubin
     * @date 2020/6/9 20:41
     */
    @RequestMapping("/getLoginUser/{token}")
    public HttpResult getUserInfo(@PathVariable String token){
        //根据token查询用户信息
        FrontUser frontUser = userService.getUserInfoFromCache(token);
        return HttpResult.ok(frontUser);
    }

}

